package org.ecshop.controllers;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.apache.catalina.User;
import org.ecshop.models.Comment;
import org.ecshop.models.Users;

import will.icecoffe.core.DataAccessException;
import will.icecoffe.core.SimpleDataAccessService;

import com.opensymphony.xwork2.ModelDriven;



public class CommentController implements ModelDriven<Object> {

	List<Comment> list = new ArrayList<Comment>();
	
	private int key;
	
	public int getKey() {
		return key;
	}

	public void setKey(int key) {
		this.key = key;
	}

	@Resource(name="DAS")
	private SimpleDataAccessService<Comment> das;
	
	private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
	
	public String index() throws DataAccessException {
	
		this.list = das.find("hql", "findCommentsByGoodsId", key);
		
		for(Comment c : list) {
			Date d = new Date(Long.valueOf(c.getAddTime()));
			c.setAddTime(sdf.format(d));
		}
		return null;
	}

	@Override
	public Object getModel() {
		return list;
	}
	
}
